﻿using AutoMapper;
using B.S.BasicData.Domain.Li;
using B.S.BasicData.Domain.SystemUsers;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interfaces;
using B.S.BasicData.Write.Api.Application.Command.L;
using MediatR;

namespace B.S.BasicData.Write.Api.Application.CommandHandler.L
{
    public class ProductManageCreateCommandHandler : IRequestHandler<ProductManageCreateCommand, ApiResult<object>>
    {
        private readonly IBaseRepository<ProductManage> _productmanagebaseRepository;
        private readonly IMapper mapper;
        public ProductManageCreateCommandHandler(IBaseRepository<ProductManage> productmanagebaseRepository,
            IMapper mapper)
        {
            _productmanagebaseRepository = productmanagebaseRepository;
            this.mapper = mapper;
        }
        public Task<ApiResult<object>> Handle(ProductManageCreateCommand request, CancellationToken cancellationToken)
        {
            var res = new ApiResult<object>();
            var entity = mapper.Map<ProductManage>(request);
            var productmangage = _productmanagebaseRepository.Add(entity);
            if (productmangage > 0)
            {
                res.Msg = "添加成功";
                res.Code = ApiEnums.Success;
                res.Data = productmangage;
            }
            return Task.FromResult(res);
        }

    }            
}
